// components/inputDialog/index.js
Component({
  lifetimes: {
    attached: function () {
      this.setData({
        submitValue: this.properties.value
      })
      wx.onKeyboardHeightChange(res => {
        if(this.data.keyBoardHeight>-1)
        this.setData({
          keyBoardHeight: res.height
        })
      })
    }
  },
  /**
   * 组件的属性列表
   */
  properties: {
    value: {
      type: String,
      value: ''
    },
    key: {
      type: String,
      value: ''
    },
    type:{
      type:String,
      value:'text'
    },
    placeholder:{
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    submitValue: "",
    keyBoardHeight:0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    valueInput: function (e) {
      this.setData({
        submitValue: e.detail.value
      })
    },
    onClose: function () {
      this.setData({
        keyBoardHeight: -1
      })
      setTimeout(()=>{
        this.triggerEvent('onClose')
      },200)
      
    },
    onSubmit: function () {
      this.setData({
        keyBoardHeight: -1
      })
      setTimeout(()=>{
        this.triggerEvent('onSubmit', {
          'value': this.data.submitValue,
          'key': this.properties.key
        })
      },200)
    
    }
  }
})